home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#21 (Jun 87)
/
basic source
/
TE DEMO2
(
.txt
)
next >
Wrap
AmigaBASIC Source Code
|
1987-05-08
|
3KB
|
112 lines
'Text Edit Demo
'By Dave Kelly
'teRec Wrap by Dave Smith
'©MacTutor 1987
OriginalEditString$="This is the first string."
endofstring=LEN(OriginalEditString$)
' Set up rectangle for TEUPDATE call
rect%(0)=20:rect%(1)=10:rect%(2)=200:rect%(3)=460
WINDOW 1,"Text Edit Demo",(15,40)-(495,330),2
EDIT FIELD 1,OriginalEditString$,(10,20)-(460,200),6,1
PRINT "Click mouse button outside of edit field or type …"
LOCATE 15,1
PRINT "The Text Edit field has been created. (EDIT FIELD statement)"
LOCATE 17,1:PRINT "TextEdit Buffer:"
oldkey$=""
GOSUB wrap: REM make textedit wrap to view rectangle
<0x00,0x07> endofstring+1,endofstring+1,WINDOW(6)
GOSUB eventloop
'Set the edit field text to a new string
NewEditString$="This the second string. (replaced old string)"
<0x00,0x07> SADD(NewEditString$),LEN(NewEditString$),WINDOW(6)
'Re-draw the edit field (needs to be re-drawn after setting new text)…
<0x00,0x07> VARPTR(rect%(0))
<0x00,0x07> VARPTR(rect%(0)),WINDOW(6)
LOCATE 15,1
PRINT "The Text Edit field has been set to a new string (TESETTEXT call)."
GOSUB eventloop
'Set the selection range…
<0x00,0x07> 1,6,WINDOW(6)
LOCATE 15,1
PRINT "The text has been selected… selection range";STRING$(50," ")
PRINT "is from before character 1 until before character 6. (TESETSELECT call)"
GOSUB eventloop
'Delete the selected text…
<0x00,0x07> WINDOW(6)
LOCATE 15,1
PRINT "The selected text has been deleted. (TEDELETE call)";STRING$(30," ")
PRINT STRING$(150," ")
GOSUB eventloop
'De-activate the edit field…
<0x00,0x07> WINDOW(6)
LOCATE 15,1
PRINT "The text has been deactivated (TEDEACTIVATE call)"
GOSUB eventloop
'Re-activate the edit field...
<0x00,0x07> WINDOW(6)
LOCATE 15,1
PRINT "The text has been activated (TEACTIVATE call)";STRING$(10," ")
GOSUB eventloop
'Insert new text at the insertion point…
TextToInsert$="-This text was inserted-"
<0x00,0x07> SADD(TextToInsert$),LEN(TextToInsert$),WINDOW(6)
LOCATE 15,1
PRINT "Text has been inserted at the insertion point. (TEINSERT call)";STRING$(20," ")
GOSUB eventloop
quit:
EDIT FIELD CLOSE 1
CLS: END
eventloop:
WHILE MOUSE(0)<>1
GOSUB TextEdit
key$=EDIT$(1)
IF key$<>oldkey$ THEN GOSUB processtext
oldkey$=key$
WEND
RETURN
processtext:
chartyped$=RIGHT$(key$,1) :REM how do you get last char typed?
LOCATE 17,18
PRINT SPACE$(4);
LOCATE 17,18
IF chartyped$<>CHR$(13) THEN PRINT chartyped$ :ELSE PRINT "CR"
RETURN
TextEdit:
myHandle#=WINDOW(6)
LOCATE 17,24:PRINT myHandle#
ptr1=PEEK(myHandle#+3)
ptr2=PEEK(myHandle#+2)
ptr3=PEEK(myHandle#+1)
ptr4=PEEK(myHandle#+0)
ptr#=(ptr3*(65536)) + (ptr2*256) + ptr1
telength1 = PEEK(ptr#+61)
teLength2=PEEK(ptr#+60)
teLength = teLength2*256+telength1
LOCATE 17,35:PRINT ptr#
LOCATE 17,45:PRINT teLength
RETURN
wrap:
GOSUB TextEdit : REM get teRec address
REM poke new values in teRec
crOnlyAdd#=ptr#+72
cronly%=0:POKE crOnlyAdd#,0 :REM turn OFF cronly
FOR i=0 TO 7
POKE ptr#+8+i,PEEK(ptr#+i): REM dest rect = view rect
NEXT i
<0x00,0x07> WINDOW(6): REM re-do line endings
RETURN